
#include "common.h"
#include <stdlib.h>
#include "getCode.h"

int j;

int main ( int argc, char** argv )
{
    SDL_Init(SDL_INIT_VIDEO);

    SDL_Surface* screen = SDL_SetVideoMode(256, 128, 24, SDL_HWSURFACE|SDL_DOUBLEBUF);
    SDL_Surface* codeSurface = SDL_LoadBMP("code_barre.bmp");
    Code1D code = getCode1D(codeSurface);

    SDL_Rect dstrect;
    dstrect.x = (screen->w - codeSurface->w) / 2;
    dstrect.y = (screen->h - codeSurface->h) / 2;

    // program main loop
    int done = 0;
    while (!done)
    {
        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = 1;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                {
                    // exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 1;
                    break;
                }
            } // end switch
        } // end of message processing

        // DRAWING STARTS HERE

        // clear screen
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

        // draw bitmap
        SDL_BlitSurface(codeSurface, 0, screen, &dstrect);

        // DRAWING ENDS HERE

        // finally, update the screen :)
        SDL_Flip(screen);
    } // end main loop

    SDL_FreeSurface(codeSurface);

    SDL_Quit();

    printf("Code is : %s", code.array);

    freeCode1D(&code);
    return 0;
}
